package com.mat.ledtester;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.hardware.Camera;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ToggleButton;

import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.ColorPicker.OnColorChangedListener;

public class MainActivity extends Activity {

    private static final int LED_NOTIFICATION_ID = 1;

    private static  ColorPicker picker = null;


	private NotificationManager nm;
	private  Notification notif;
    
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
       
        	
		nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
        notif = new Notification();
	    picker = (ColorPicker) findViewById(R.id.picker);

	    
	    picker.setOnColorChangedListener(new OnColorChangedListener() {
			
			@Override
			public void onColorChanged(int color) {
				
				updateColor(color);
				
			}
		});
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    public void toggleLed(View view){
    	
    	
    	ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
	    
    	if(!toggleButton.isChecked()){
    		  nm.cancel(LED_NOTIFICATION_ID);    		
    	}
    	  	
    }
    
    public void updateColor(int color){
    	
  
    	EditText editText = (EditText) findViewById(R.id.editText2);
    	editText.setText(String.valueOf(picker.getColor()));
    	editText.setTextColor(color);

	    notif.ledARGB = color;
	    notif.flags = Notification.FLAG_SHOW_LIGHTS ;
	    notif.ledOnMS = 100; 
	    notif.ledOffMS = 100; 
	    nm.notify(LED_NOTIFICATION_ID, notif);
    	
    }
    
}
